<?php

    require_once APPPATH . 'core/BaseDAO.php';

    class TestDAO extends BaseDAO {

        function __construct() {
            parent::__construct();
        }

        public function checkDB(){
            
            return $this->em->dbutil->database_exists('MetodosDB');
            
        }
        
        public function checkTable($table){
            
            $CI = & get_instance();
            $rows = $CI->db->query('SELECT * FROM "BD_Operativa".'.$table);
            $CI->db->close();
            return empty($rows) ? FALSE : TRUE;
            
        }
        
        public function getCountSociosTest($tipoDocumento = '',$numeroDocumento = '',$apellido = ''){
        
            try {

                $comienzo = "SELECT count(s.id) FROM models\M_socio s JOIN s.tipo_documento t";

                $where = "";

                if(!($tipoDocumento == '' && $numeroDocumento == '' && $apellido == '')){

                    $where .= ' WHERE ';

                    $where .= "s.apellido LIKE ".(($apellido == '') ? "'%'" : " '%".$apellido."%' ");

                    $where .= ($tipoDocumento == '' || $tipoDocumento == 0) ? "" : " AND t.id = ".$tipoDocumento;

                    $where .= ($numeroDocumento == '') ? "" : " AND s.numero_documento = ".$numeroDocumento;

                }

                $consulta = $comienzo.$where.'';

                $query = $this->em->createQuery($consulta);

                $socios = $query->getResult();

                return empty($socios) ? FALSE : $socios[0][1];

            } catch (Exception $e) {
                return FALSE;
            }
        
        }
        
        public function listarCampos($tabla){
            
            $CI = & get_instance();
            $query = $CI->db->query('SELECT * FROM "BD_Operativa".'.$tabla);
            
            return $query->list_fields();
            
        }

    }
?>
